<template>
  <div class="allMembers">
    <div class="search">
      <div>
        <label>搜索：</label>
      </div>

      <el-input v-model="listParams.keyword" placeholder="ID/昵称"></el-input>
      <div>
        <el-button @click='searchKeyWord' type="primary">搜索</el-button>
      </div>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="id" width="90">
        <template slot-scope="scope">
            <span @click='userDetails(scope.row)' class="link-type">{{scope.row.id}}</span>
        </template>
      </el-table-column>
      <el-table-column label="头像" width="90">
        <template slot-scope="scope">
            <div class='imgBox'>
                <img :src="scope.row.avatar" alt="">
            </div>
        </template>
      </el-table-column>
       <el-table-column prop="name" label="姓名"></el-table-column>
       <el-table-column prop="code" label="推荐码"></el-table-column>
       <el-table-column prop="mobile" label="手机号"></el-table-column>
      <el-table-column label="注册时间">
        <template slot-scope="scope">
            <!-- {{ scope.row.time | parseTime('{y}-{m}-{d} {h}:{i}') }} -->
            <span>{{scope.row.createTime | parseTime('{y}-{m}-{d} {h}:{i}')}}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份">
        <template slot-scope="scope">
            <span>{{getIdentity(scope.row)}}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否认证">
        <template slot-scope="scope">
            <span>{{getauthStatus(scope.row)}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="commender" label="推荐人">
        <template slot-scope="scope">
            <span @click='userDetailsCommender(scope.row)' class="link-type">{{getInviteUserId(scope.row)}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="membership" label="直推会员人数"></el-table-column>
      <el-table-column prop="classTwoMembership" label="二级会员人数"></el-table-column>
      <el-table-column prop="orderNumber" label="订单数"></el-table-column> -->
      <el-table-column label="余额">
        <template slot-scope="scope">
            <span @click='openbillDetails(scope.row)' class="link-type">{{getShowDeciemal(scope.row.money)}}</span>
        </template>
      </el-table-column>
     </el-table>
    <el-pagination
      class="pagination"
      background
      @current-change="handleCurrentChange"
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>

    <!-- 余额明细 -->
    <billDetails ref="billDetails"></billDetails>
  </div>
</template>


<script>
import {ajax} from '@/api';
import { parseTime } from '@/utils';
import {getToken} from "@/utils/auth";
import billDetails from "./components/billDetails";
import numberFormat from '@/api/numberFormat';
export default {
  name: "distributor",
  data() {
    return {
      total:0,
      addMarketDialogVisible:false,
      input: "",
      form:{
          targetUserId:'',
          mobile:13800138000,
          password:'P@ssw0rd',
          role:'dealer',
          name:'',
          gender:'',
          areaId:'',
          inviteUserId:'',
          token:getToken()
      },
      tableData: [],
      listParams:{
        role:'dealer',
        auth:0,
        keyword:'',
        start:0,
        limit:10,
        token:getToken()
      },
      user:[]
    };
  },
  methods: {
    userDetailsCommender(data){
        this.$router.push({name:'userDetails',params:{id:data.inviteUserId}});
      },
    getShowDeciemal(money){
      return numberFormat.showDecimal(money);
    },
    searchKeyWord(){
      if(this.listParams.keyword === ''){
        return this.$message.error('ID/昵称不能为空');
      }
      this.getList();
    },
    //推荐人
    getInviteUserId(data){
        if(data.inviteUserId > 0){
          return this.user[data.inviteUserId].name;
        }else{
          return '--';
        }
    },
    //身份
    getIdentity(data){
      let str = '用户';
      if(data.role.admin){
        str = str + '、管理员';
      }

      if(data.role.dealer){
        str = str + '、经销商';
      }


      if(data.role.issue){
        str = str + '、发行商';
      }

      if(data.role.market){
        str = str + '、市场人员';
      }
      return str;
    },
    //是否认证
    getauthStatus(data){
      return data.authStatus.text;
    },
    
    addMarketPersonnal() {
        this.addMarketDialogVisible = true;
    },
    vails(){
      if(this.form.targetUserId === ''){
        return this.$message.error('请输入用户ID');
      }
      if(this.form.inviteUserId === ''){
        return this.$message.error('请输入推荐市场人员ID');
      }
    },
    openbillDetails(item) {
      this.$refs.billDetails.openBill(item);
    },
    userDetails(data){
        this.$router.push({name:'userDetails',params:{id:data.id}});
    },
    handleCurrentChange(val){
        this.listParams.start = (val - 1) * this.listParams.limit;
        this.getList();
    },
    //经销商列表
    getList(){
      ajax('users',this.listParams).then((res) => {
        console.log(res);
        if(res.data.status){
          this.total = res.data.total;
          this.tableData = res.data.data;
          this.user = res.data.users;
          console.log(this.tableData);
        }
      });
    }
  },
  mounted(){
    this.getList();
  },
  components: {
    billDetails
  }
};
</script>


<style lang="less" scoped>
.allMembers {
  padding: 1rem;
  .search {
    display: flex;
    margin: 0.5rem 0 1rem 0;
    div:first-child {
      width: 3.5rem;
      line-height: 2.5rem;
      label {
        font-weight: 400;
      }
    }
    div:nth-child(2) {
      width: 11rem;
      margin-right: 1rem;
    }
    div:nth-child(3){
        margin-right: 1rem;
    }
  }
  .imgBox {
    width: 50px;
    height: 50px;
    margin: 0 auto;
    img {
      width: 100%;
      height: 100%;
      border-radius: 50px;
    }
  }
  .pagination{
    text-align: right;
    margin: 1rem 0;
  }
}
</style>
